package nacos

import (
	"github.com/nacos-group/nacos-sdk-go/v2/clients"
	"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
	"github.com/nacos-group/nacos-sdk-go/v2/vo"
)

// 服务注册
func getNamingClient() (naming_client.INamingClient, error) {
	return clients.NewNamingClient(initNacos())
}

// 注册服务 ip 端口
func RegisterServiceInstance(ip, service, group_name string, port int, weight float64) error {
	client, err := getNamingClient()
	if err != nil {
		return err
	}
	_, err = client.RegisterInstance(vo.RegisterInstanceParam{
		Ip:          ip,
		Port:        uint64(port),
		ServiceName: service,
		GroupName:   group_name,
		Enable:      true,
		Healthy:     true,
		Weight:      weight,
	})
	return err
}
